<script src="../../main.js"></script>
<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-people"></i> 视频管理
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-button
                        type="primary"
                        icon="el-icon-lx-roundadd"
                        class="handle-del mr10"
                        @click="addItem"
                        v-if="globalPermission.news.add"
                >新增
                </el-button>
                <el-input v-model="query.title" placeholder="标题" class="handle-input mr10"></el-input>
                <el-select v-model="query.status" placeholder="状态" class="handle-input mr10">
                    <el-option
                            v-for="item in statusOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
                <template>
                    <el-date-picker
                            v-model="timeValue"
                            type="daterange"
                            align="right"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            :picker-options="pickerOptions"
                            class="mr10">
                    </el-date-picker>
                </template>
                <el-button type="primary" icon="el-icon-search"  @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column prop="title" label="标题"></el-table-column>
                <el-table-column prop="status" size="10px" label="状态">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.status==0" type="warning">下架</el-tag>
                        <el-tag v-if="scope.row.status==1" type="info">上架</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="封面" align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-lx-attention"
                                @click="handleImage(scope.row.id,scope.row.coverImg)"
                        >查看/上传</el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="userName" label="演讲者"></el-table-column>
                <el-table-column prop="viewCount" label="观看量"></el-table-column>
                <el-table-column prop="createdTime" label="创建时间"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-edit"
                                @click="handleEdit(scope.row.id)"
                                v-if="globalPermission.news.edit"
                        >查看编辑
                        </el-button>
                        <el-button
                                type="text"
                                icon="el-icon-edit"
                                @click="handleVideoManager(scope.row.id)"
                                v-if="globalPermission.news.edit"
                        >课程管理
                        </el-button>
                        <el-button
                                type="text"
                                icon="el-icon-edit"
                                @click="handleStatus(scope.row.id,scope.row.status)"
                                v-if="globalPermission.news.one && scope.row.status==0"
                        >上架
                        </el-button>
                        <el-button
                                type="text"
                                icon="el-icon-edit"
                                @click="handleStatus(scope.row.id,scope.row.status)"
                                v-if="globalPermission.news.two && scope.row.status==1"
                        >下架
                        </el-button>
                        <el-button
                                type="text"
                                icon="el-icon-delete"
                                class="red"
                                @click="handleDelete(scope.row.id, scope.row)"
                                v-if="globalPermission.news.delete"
                        >删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="total, prev, pager, next"
                        :current-page="query.pageNum"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 图片弹出框 -->
        <el-dialog title="封面图片" :visible.sync="imageVisible" width="40%">
            <el-table
                    :data="picData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
            >
                <el-table-column prop="imageName" label="图片(点击预览大图)" align="center">
                    <template slot-scope="scope">
                        <el-image
                                class="table-td-thumb"
                                :src="picData[scope.$index]"
                                :preview-src-list="picData"
                        ></el-image>
                    </template>
                </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
               <el-upload
                       ref="uploadPicture"
                       class="upload-demo"
                       action="/manager/tencent/uploadVideoImg"
                       :headers="getToken"
                       :before-upload="beforeUpload"
                       :data="uploadData"
                       :on-success="refreshPic"
                       multiple
               >
                    <el-button size="medium" type="primary" v-if="globalPermission.news.addpic">上传封面</el-button>
                    <div slot="tip" class="el-upload__tip">友情提示：图片操作实时更新</div>
                </el-upload>
            </span>
        </el-dialog>

        <!-- 视频弹出框 -->
        <el-dialog title="预览视频" :visible.sync="videoVisible" width="40%">
           <video-player class="vjs-custom-skin" :options="playerOptions"></video-player>
        </el-dialog>

        <!-- 编辑弹出框 -->
        <el-dialog title="查看/编辑" :visible.sync="editVisible" width="50%">
            <el-form ref="form" :model="form" label-width="170px">
                <el-form-item label="标题" >
                    <el-input v-model="form.title"></el-input>
                </el-form-item>
                <el-form-item label="摘要" >
                    <el-input v-model="form.summary"></el-input>
                </el-form-item>
                <el-form-item label="演讲人" >
                    <el-input v-model="form.userName"></el-input>
                </el-form-item>
                <el-form-item label="标签">
                    <el-select v-model="form.tagId" placeholder="标签" class="handle-input mr15">
                        <el-option
                                v-for="item in colOptions"
                                :key="item.key"
                                :label="item.label"
                                :value="item.key">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="视频介绍">
                    <quill-editor ref="myTextEditor" v-model="form.introduce" :options="editorOption3"></quill-editor>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="clean">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 编辑课程弹出框 -->
        <el-dialog title="查看/编辑课程信息" :visible.sync="editVideoItemVisible" width="50%">
            <el-form ref="form" :model="form" label-width="170px">
                <el-form-item label="视频id" >
                    <el-input v-model="form.videoId" readonly></el-input>
                </el-form-item>
                <el-form-item label="课程名字" >
                    <el-input v-model="form.videoTitle"></el-input>
                </el-form-item>
                <el-form-item label="课程章节" >
                    <el-input v-model="form.chapter" placeholder="填入课程号即可,例如第一章节就填写:1"></el-input>
                </el-form-item>
                <el-form-item label="视频">
                    <video-player class="vjs-custom-skin":options="playerOptionsItem"></video-player>
                    <el-input v-model="form.videoUrl" id="videoUrl" v-if="condition" ></el-input>
                     <el-input v-model="form.fileidTx" id="fileidTx" v-if="condition" ></el-input>
                </el-form-item>
                <el-form-item label="视频操作">
                <div class="upload_video" id="upload_video">
                     <el-upload
                     class="upload-demo"
                     ref="upload"
                     action="#"
                     :http-request="uploadVideo"
                     :limit="1"
                     :on-remove="handleRemove"
                     :on-change="handleChange"
                     :auto-upload="false">
                         <el-button slot="trigger" size="small" type="primary">选取视频</el-button>
                         <el-progress class="progress" :text-inside="true" :stroke-width="18" :percentage="progress" status="exception"></el-progress>
                       <div slot="tip" class="el-upload__tip">只能上传mp4文件，且不超过500M</div>
                       <el-button type="success" size="small" @click="submitUpload">点击上传</el-button>
                     </el-upload>
                     <img id="video_img" style="width:90px;height:160px;display:none">
                  </div>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="cleanVideoItem">取 消</el-button>
                <el-button type="primary" @click="saveItemEdit">确 定</el-button>
            </span>
        </el-dialog>


        <!-- 编辑课程列表 -->
        <el-dialog title="查看/编辑课程" :visible.sync="editVideoVisible" width="70%">
             <div class="handle-box">
                <el-button
                        type="primary"
                        icon="el-icon-lx-roundadd"
                        class="handle-del mr10"
                        @click="addVideoItem"
                        v-if="globalPermission.news.add"
                >添加课程
                </el-button>
            </div>
            <el-table
                    :data="tableItemData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
            >
                <el-table-column prop="videoId" label="视频id"></el-table-column>
                <el-table-column prop="id" label="课程id"></el-table-column>
                <el-table-column prop="fatherTitle" label="视频标题"></el-table-column>
                <el-table-column prop="videoTitle" label="课程名称"></el-table-column>
                <el-table-column label="视频内容" align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-lx-attention"
                                @click="handleVideo(scope.row.id,scope.row.videoUrl)"
                        >查看</el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="chapter" label="课程章节"></el-table-column>
                <el-table-column prop="videoTime" label="课程时长"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-edit"
                                @click="handleItemEdit(scope.row.id)"
                                v-if="globalPermission.news.edit"
                        >查看编辑
                        </el-button>
                        <el-button
                                type="text"
                                icon="el-icon-delete"
                                class="red"
                                @click="handleDeleteItem(scope.row.id, scope.row)"
                                v-if="globalPermission.news.delete"
                        >删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>
    </div>
</template>

<script>
    import {upload,getAllItemNews,getVodSignatureUrl,getAllNews, delNews,delNewsItem, saveNews,saveItemNews, editNews,editItemNews, getDetail,getDetailItem, saveStatus} from '../../api/news';
    import {getAllTags} from '../../api/tags'
    import TcVod from 'vod-js-sdk-v6'
    import 'quill/dist/quill.snow.css' // 富文本编辑器外部引用样式  三种样式三选一引入即可
    //import 'quill/dist/quill.core.css'
    //import 'quill/dist/quill.bubble.css'
    import '@/utils/size-set.css';
    import {quillRedefine} from 'vue-quill-editor-upload'
    import { quillEditor,Quill } from 'vue-quill-editor';
    import {container, ImageExtend, QuillWatch} from 'quill-image-extend-module'
    Quill.register('modules/ImageExtend', ImageExtend);
    let fontSizeStyle = Quill.import('attributors/style/size');
    fontSizeStyle.whitelist = ['10px', '12px', '14px', '16px','18px','20px', '22px','24px', '26px', '28px','30px','32px', '36px','38px', '40px','45px', '50px', false];
    Quill.register(fontSizeStyle, true);
    //引入video样式
    import 'video.js/dist/video-js.css'
    import 'vue-video-player/src/custom-theme.css'
    //引入hls.js
    var getSignUrlRequest = {url:"/manager/video/getSignUrl"};
    var queryItemRequest = {url: "/manager/video/videoItemList"};
    var queryRequest = {url: "/manager/video/videoList"};
    var addRequest = {url: "/manager/video/addVideo"};
    var addItemRequest  = {url: "/manager/video/addVideoItem"};
    var updateRequest = {url: "/manager/video/updateVideo"};
    var updateItemRequest = {url: "/manager/video/updateVideoItem"};
    var delItemRequest = {url: "/manager/video/delVideoItem"};
    var delRequest = {url: "/manager/video/delVideoById"};
    var getDetailRequest = {url:"/manager/video/getVideoInfo"};
    var getDetailItemRequest = {url:"/manager/video/videoItemInfo"};
    var approveRequest = {url:"/manager/video/updateStatus"};
    var queryTagsRequest = {url:"/manager/tags/getTags"};
    export default {
        name: 'usertable',
        data() {
            return {
                fileList: [],
                progress: 0,
                imgBase: '',
                fileId: '',
                query: {
                    artStatus: '',
                    titleDesc: '',
                    colId:'',
                    pcfirst:'',
                    pageNum: 1,
                    pageSize: 10,
                    startTime:'',
                    endTime:''
                },
                delQuery:{
                    articleId:'',
                    index:''
                },
                statusQuery:{
                    id:'',
                    status
                },
                condition: false,
                colOptions:this.getColOptions(),
                editorOption2:{},
                editorOption3: {
                    modules: {
                        toolbar: {
                            container: [
                                //["bold", "italic", "underline", "strike"], //加粗，斜体，下划线，删除线
                                //["blockquote", "code-block"], //引用，代码块

                                //[{ header: 1 }, { header: 2 }], // 标题，键值对的形式；1、2表示字体大小
                                //[{ list: "ordered" }, { list: "bullet" }], //列表
                                //[{ script: "sub" }, { script: "super" }], // 上下标
                                [{ indent: "-1" }, { indent: "+1" }], // 缩进
                                //[{ direction: "rtl" }], // 文本方向
                                [{ size: fontSizeStyle.whitelist}], // 字体大小  ["small", false, "large", "huge"]
                                //[{ size:['10px', false, '12px', '14px', '16px', '18px', '20px', '22px', '24px', '26px', '28px', '30px', '33px', '36px', '40px']}],
                                //[{ header: [1, 2, 3, 4, 5, 6, false] }], //几级标题

                                //[{ color: [] }, { background: [] }], // 字体颜色，字体背景颜色
                                //[{ align: [] }], //对齐方式
                                ["clean"] //上传图片、上传视频 //清除字体样式
                            ],
                            handlers: {
                                'image': function () {
                                    QuillWatch.emit(this.quill.id)
                                }
                            }
                        }
                    }
                },
                globalPermission: this.getPermission(),
                getToken:{'auth-token':localStorage.getItem('token')},
                uploadData:null,
                picData :[],
                tableData: [],
                tableItemData: [],
                multipleSelection: [],
                delList: [],
                editVisible: false,
                editVideoVisible:false,
                editVideoItemVisible:false,
                imageVisible:false,
                videoVisible:false,
                editRolesVisible: false,
                formIdShow: false,
                isCurEdit: false,
                pageTotal: 0,
                videoUrl:'',
                form: {},
                statusForm:{},
                idx: -1,
                id: -1,
                status:0,
                statusOptions: [{
                    value: 0,
                    label: '下架'
                }, {
                    value: 1,
                    label: '上架'
                }],
                editor: null,   // 富文本编辑器对象
                content: "", // 富文本编辑器默认内容
                editorOption: { //  富文本编辑器配置
                    placeholder: '请输入正文',
                    modules:{
                        toolbar:{
                            container:[
                                ["bold", "italic", "underline", "strike"], //加粗，斜体，下划线，删除线
                                ["blockquote", "code-block"], //引用，代码块

                                [{ header: 1 }, { header: 2 }], // 标题，键值对的形式；1、2表示字体大小
                                [{ list: "ordered" }, { list: "bullet" }], //列表
                                [{ script: "sub" }, { script: "super" }], // 上下标
                                [{ indent: "-1" }, { indent: "+1" }], // 缩进
                                [{ direction: "rtl" }], // 文本方向
                                //[{ size: fontSizeStyle.whitelist}], // 字体大小  ["small", false, "large", "huge"]
                                [{ size:['10px', false, '12px', '14px', '16px', '18px', '20px', '22px', '24px', '26px', '28px', '30px', '33px', '36px', '40px']}],
                                [{ header: [1, 2, 3, 4, 5, 6, false] }], //几级标题

                                [{ color: [] }, { background: [] }], // 字体颜色，字体背景颜色
                                [{ align: [] }], //对齐方式
                                ["image"],["clean"] //上传图片、上传视频 //清除字体样式
                            ]
                        }
                    }
                },
                 playerOptionsItem: {
                                    playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
                                    autoplay: false, //如果true,浏览器准备好时开始回放。
                                    controls: true, //控制条
                                    preload: 'auto', //视频预加载
                                    muted: false, //默认情况下将会消除任何音频。
                                    loop: false, //导致视频一结束就重新开始。
                                    language: 'zh-CN',
                                    aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
                                    fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
                                    sources: [{
                                        type: 'video/mp4',
                                        src: ''//你所放置的视频的地址，最好是放在服务器上
                                    }],
                                    //poster: "http://39.106.117.192:8080/static/indexImg.png", //你的封面地址（覆盖在视频上面的图片）
                                    width: document.documentElement.clientWidth,
                                    height: document.documentElement.offsetHeight,
                                    notSupportedMessage: '此视频暂无法播放，请稍后再试' //允许覆盖Video.js无法播放媒体源时显示的默认信息。
                                },
                playerOptions: {
                    playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
                    autoplay: false, //如果true,浏览器准备好时开始回放。
                    controls: true, //控制条
                    preload: 'auto', //视频预加载
                    muted: false, //默认情况下将会消除任何音频。
                    loop: false, //导致视频一结束就重新开始。
                    language: 'zh-CN',
                    aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
                    fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
                    sources: [{
                        type: 'video/mp4',
                        src: ''//你所放置的视频的地址，最好是放在服务器上
                    }],
                    //poster: "http://39.106.117.192:8080/static/indexImg.png", //你的封面地址（覆盖在视频上面的图片）
                    width: document.documentElement.clientWidth,
                    height: document.documentElement.offsetHeight,
                    notSupportedMessage: '此视频暂无法播放，请稍后再试' //允许覆盖Video.js无法播放媒体源时显示的默认信息。
                },
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                timeValue:'',
            };
        },
        components:{
            quillEditor,quillRedefine
        },
        created() {
            queryRequest.data = this.query;
            this.getData();
            this.editorOption2 = quillRedefine(
                {
                    // 图片上传的设置
                    uploadConfig: {
                        action:  'http://140.143.37.174:9092/manager/file/uploadImg',  // 必填参数 图片上传地址
                        // 必选参数  res是一个函数，函数接收的response为上传成功时服务器返回的数据
                        // 你必须把返回的数据中所包含的图片地址 return 回去
                        res: (res) => {
                            return res.data  // 这里切记要return回你的图片地址
                        },
                        name:'file'  //图片上传的参数名，也即是后台接口接受的参数名
                    }
                }
            )
        },
        methods: {
            // 获取数据
            getData() {
                //获取新闻列表
                getAllNews(queryRequest).then(res => {
                    this.tableData = res.data.list;
                    this.pageTotal = res.data.total;
                });
            },
            // 获取签名  这里的签名请求是由后端提供的，只需要拿到后端给的签名请求即可
            getVodSignature(){
                return getVodSignatureUrl(getSignUrlRequest).then(res=>{
                   return  res.data;
                });
            },

            // 文件列表改变时  将文件列表保存到本地
            handleChange (file, fileList) {
              this.fileList = fileList
            },
            // 点击上传时
            submitUpload () {
              if (this.fileList.length < 1) return this.$MessageBox('请先选取视频，再进行上传', '提示')
              this.uploadVideo()
            },
            // 自定义上传
            uploadVideo (e) {
              // 当
              console.log(this.fileList[0].raw)
              if (this.fileList.length < 1) {
                window.alert('您还没有选取文件')
              } else {
                //必须以函数的形式返回  sdk参数限制
                const ddd = this.getVodSignature()
                const getSignature = async () => {
                  const data = await this.getVodSignature()
                  return data
                }
                const tcVod = new TcVod({
                  getSignature: getSignature // 获取上传签名的函数
                })
                // 获取通过elementui上传到本地的文件  因为参数类型必须为file 不能直接以对象的形式传输
                const mediaFile = this.fileList[0].raw
                const uploader = tcVod.upload({
                  mediaFile: mediaFile
                })
                // 监听上传进度
                uploader.on('media_progress', info => {
                  this.progress = parseInt(info.percent * 100)
                })
                // 上传结束时，将url存到本地
                uploader.done().then(doneResult => {
                  // 保存地址
                  // console.log(this.fileId)
                  this.fileId = doneResult.fileId
                  this.playerOptionsItem.sources[0].src=doneResult.video.url;
                  this.form.videoUrl =doneResult.video.url;
                  this.form.fileidTx =this.fileId;
                })
              }
            },
            // 点击删除时
            handleRemove (file, fileList) {
              console.log(file, fileList.length)
            },
            clean(){
                this.editVisible=false;
                this.editVideoVisible = false;
                this.editVideoItemVisible = false;
                this.handleSearch();
            },
           cleanVideoItem(){
                this.videoId=this.form.videoId;
                this.editVideoItemVisible = false;
                this.handleVideoManager(this.videoId);
            },
            handleAvatarSuccess(res, file) {
                this.playerOptions.sources[0].src=res.data;
            },
            //审核
            handleStatus(id,status){
                this.id= id;
                this.status=status;
                this.titleMsg = "确定要上架吗?";
                if(status == 1){
                    this.titleMsg = "确定要下架吗?";
                    this.status=0;
                }else{
                    this.status=1;
                }
                // 二次上下架
                this.$confirm(this.titleMsg, '提示', {
                    type: 'warning'
                }).then(() => {
                    this.statusQuery.id=this.id;
                    this.statusQuery.status=this.status;
                    approveRequest.data = this.statusQuery;
                    saveStatus(approveRequest).then(res => {
                        if (res.code == 0) {
                            this.$message.success(`成功`);
                            this.handleSearch();
                        } else {
                            this.$message.error(res.message);
                        }
                    });
                }).catch(() => {
                });
            },
            getPermission() {
                return JSON.parse(sessionStorage.getItem("permission"));
            },
             beforeUpload (file) {
                this.uploadData = {id:this.id};
                let promise = new Promise((resolve) => {
                    this.$nextTick(function () {
                        resolve(true);
                    });
                });
                return promise; //通过返回一个promis对象解决
            },
            // 打开图片窗口
            handleImage(id,imgs) {
                this.id=id;
                if (imgs ==='' || imgs===null){

                }else{
                    this.picData = imgs.split(',');
                }
                this.imageVisible = true;
            },
            // 打开视频窗口
            handleVideo(id,videoUrl) {
                this.id=id;
                this.playerOptions.sources[0].src=videoUrl;
                this.videoVisible = true;
            },
           refreshPic(response){
                this.imageVisible = false;
                this.handleSearch();
            },
            // 触发搜索按钮
            handleSearch() {
                this.query.startTime=this.timeValue[0];
                this.query.endTime=this.timeValue[1];
                this.$set(this.query, 'pageNum', 1);
                this.getData();
            },
            // 删除操作
            handleDelete(id, row) {
                // 二次确认删除
                this.$confirm('确定要删除吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    delRequest.id = id;
                    delNews(delRequest).then(res => {
                        if (res.code == 0) {
                            this.$message.success(`删除成功`);
                            this.handleSearch();
                        } else {
                            this.$message.error(res.message);
                        }
                    });
                }).catch(() => {
                });
            },

            // 删除操作
            handleDeleteItem(id, row) {
                // 二次确认删除
                this.$confirm('确定要删除？', '提示', {
                    type: 'warning'
                }).then(() => {
                    delItemRequest.id = id;
                    delNewsItem(delItemRequest).then(res => {
                        if (res.code == 0) {
                            this.$message.success(`删除成功`);
                            this.handleVideoManager(row.videoId);
                        } else {
                            this.$message.error(res.message);
                        }
                    });
                }).catch(() => {
                });
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },

            // 新增
            addItem() {
                this.form={};
                this.editVisible = true;
                this.isCurEdit = false;
            },
            // 编辑操作
            handleEdit(id) {
                this.id = id;
                getDetailRequest.id =id;
                getDetail(getDetailRequest).then(res=>{
                   this.form = res.data;
                   this.playerOptions.sources[0].src = res.data.videoUrl;
                });
                this.editVisible = true;
                this.isCurEdit = true;
            },
            // 编辑视频下课程操作
            handleItemEdit(id) {
                this.videoId = id;
                getDetailItemRequest.id =id;
                getDetailItem(getDetailItemRequest).then(res=>{
                   this.form = res.data;
                   this.playerOptionsItem.sources[0].src=res.data.videoUrl;
                });
                this.editVideoItemVisible = true;
                this.progress = 0;
                this.isCurEdit = false;
                this.isCurItemEdit = true;
            },
            // 新增课程
            addVideoItem() {
                this.form={};
                this.editVideoItemVisible = true;
                this.progress = 0;
                this.isCurEdit = false;
                this.isCurItemEdit = false;
                this.form.videoId = this.id;
                this.playerOptionsItem.sources[0].src=null;
            },
            // 编辑课程操作
            handleVideoManager(id) {
                this.editVideoVisible = false;
                //获取新闻列表
                this.id = id;
                queryItemRequest.id =id;
                getAllItemNews(queryItemRequest).then(res => {
                    this.tableItemData = res.data;
                });
                this.id = id;
                this.editVideoVisible = true;
            },
            // 保存编辑
            saveEdit() {
                if (this.isCurEdit) {
                    updateRequest.data = this.form;
                    editNews(updateRequest).then(res => {
                        console.log(res);
                        if (res.code == 0) {
                            this.$message.success(`修改成功`);
                            this.editVisible = false;
                            this.editVideoVisible = false;
                            this.handleSearch();
                        } else {
                            this.$message.error(res.message);
                        }
                    });
                } else {
                    addRequest.data = this.form;
                    saveNews(addRequest).then(res => {
                        console.log(res);
                        if (res.code == 0) {
                            this.$message.success(`新增成功`);
                            this.editVisible = false;
                            this.editVideoVisible = false;
                            this.handleSearch();
                        } else {
                            this.$message.error(res.message);
                        }
                    });
                }
            },

            getColOptions(){
                const data = [];
                queryTagsRequest.data ={
                    pageNum: 1,
                    pageSize: 100
                };
                getAllTags(queryTagsRequest).then(res =>{
                    res.data.list.forEach(function (tabs) {
                        data.push({
                            label: tabs.tname,
                            key: tabs.id
                        });
                    });
                });
                return data;
            },

            // 保存编辑
            saveItemEdit() {
                this.videoId=this.form.videoId;
                if (this.isCurItemEdit) {
                    updateItemRequest.data = this.form;
                    editItemNews(updateItemRequest).then(res => {
                        console.log(res);
                        if (res.code == 0) {
                            this.$message.success(`修改成功`);
                            this.editVisible = false;
                            this.editVideoVisible = false;
                            this.editVideoItemVisible = false;
                            this.handleVideoManager(this.videoId);
                        } else {
                            this.$message.error(res.message);
                        }
                    });
                } else {
                    addItemRequest.data = this.form;
                    saveItemNews(addItemRequest).then(res => {
                        console.log(res);
                        if (res.code == 0) {
                            this.$message.success(`新增成功`);
                            this.editVisible = false;
                            this.editVideoVisible = false;
                            this.handleSearch();
                            this.editVideoItemVisible = false;
                            this.handleVideoManager(this.videoId);
                        } else {
                            this.$message.error(res.message);
                        }
                    });
                }
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageNum', val);
                this.getData();
            }
        }
    };
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 130px;
        display: inline-block;
    }

    .table {
        width: 100%;
        font-size: 14px;
    }

    .red {
        color: #ff0000;
    }

    .mr10 {
        margin-right: 10px;
    }

    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }

    .show {
        display: block;
    }

    .hide {
        display: none;
    }

    .checkbox-rows {
        width: 130px;
        margin-top: 10px;
    }

    .el-checkbox.is-bordered + .el-checkbox.is-bordered {
        margin-left: 0px;
    }
</style>
